package com.rqf.ls.service.impl;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rqf.ls.service.ICommonDataService;
import com.rqf.ls.service.IManagementQuestion;
import com.server.date.DateType;
import com.server.date.DateUtil;
import com.server.web.DataVector;
import com.server.web.RequestInput;

@Service("ManagementQuestion")
public class ManagementQuestion implements IManagementQuestion {
	
	@Autowired
	private ICommonDataService commonDataService;

	/**
	 * 问题列表，带分页
	 * @param requestInput
	 * @return
	 * @author ServerZhang
	 * @date 2016年5月19日
	 */
	@Override
	public DataVector<Map<String, Object>> getList(RequestInput requestInput){
		String table = "V_QUESTION_SELECT";
		String _whereStr = "";
		String sortStr = "createtime desc";
		DataVector<Map<String, Object>> listData = commonDataService.getListData(table, _whereStr, sortStr, requestInput);
		return listData;
	}
	 /**
	 * 问题列表中的唯一日期列表
	 * @param requestInput
	 * @return
	 * @author ServerZhang
	 * @date 2016年5月19日
	 */
	@Override
	public List<Map<String, Object>> dateList(){
		String table = "QUESTION";
		String fieldStr = "createdate";
		String whereStr = "";
		String sortStr = "createdate desc";
		List<Map<String, Object>> dateList = commonDataService.getFieldList(table, fieldStr, whereStr, sortStr);
		Iterator<Map<String, Object>> iterator = dateList.iterator();
		while(iterator.hasNext()){
			Map<String, Object> next = iterator.next();
			Object dateObj = next.get("CREATEDATE");
			if (dateObj != null) {
				String dateStr = DateUtil.getDateStr((Date)dateObj, DateType.YYYY_MM_DD);
				next.put("CREATEDATE", dateStr);
			}
		}
		return dateList;
	}
}
